package pl.puntin.punclient.view;

import java.awt.Dimension;

import javax.swing.JPanel;



import pl.puntin.punclient.controller.Controller;

public class LoginView2 extends JPanel {
    private javax.swing.JTextField ipField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    public javax.swing.JButton loginButton;
    private javax.swing.JTextField loginField;
    private javax.swing.JTextField portField;
    private Controller controler;
	    /**
	     * Creates new form NewJPanel
	     */
	    public LoginView2(Controller contr) {
	    	controler = contr;
	    	setPreferredSize(new Dimension(250, 350));
	        initComponents();
	    }
                         
	    private void initComponents() {

	        jLabel1 = new javax.swing.JLabel();
	        loginField = new javax.swing.JTextField();
	        jLabel2 = new javax.swing.JLabel();
	        ipField = new javax.swing.JTextField();
	        jLabel3 = new javax.swing.JLabel();
	        portField = new javax.swing.JTextField();
	        loginButton = new javax.swing.JButton();

	        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
	        jLabel1.setText("Login");

	        loginButton.addActionListener(new java.awt.event.ActionListener() {
	            public void actionPerformed(java.awt.event.ActionEvent evt) {
	                loginButtonActionPerformed(evt);
	            }
	        });

	        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
	        jLabel2.setText("Ip Hosta");

	        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
	        jLabel3.setText("Port");

	        loginButton.setText("Zaloguj");

	        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
	        this.setLayout(layout);
	        layout.setHorizontalGroup(
	            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	            .addGroup(layout.createSequentialGroup()
	                .addGap(78, 78, 78)
	                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
	                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
	                    .addComponent(loginField)
	                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
	                    .addComponent(ipField)
	                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
	                    .addComponent(portField)
	                    .addComponent(loginButton, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
	                .addContainerGap(78, Short.MAX_VALUE))
	        );
	        layout.setVerticalGroup(
	            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	            .addGroup(layout.createSequentialGroup()
	                .addGap(44, 44, 44)
	                .addComponent(jLabel1)
	                .addGap(18, 18, 18)
	                .addComponent(loginField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
	                .addGap(18, 18, 18)
	                .addComponent(jLabel2)
	                .addGap(18, 18, 18)
	                .addComponent(ipField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
	                .addGap(18, 18, 18)
	                .addComponent(jLabel3)
	                .addGap(18, 18, 18)
	                .addComponent(portField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
	                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 43, Short.MAX_VALUE)
	                .addComponent(loginButton)
	                .addGap(33, 33, 33))
	        );
	    }                       

	    
		private void loginButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
			loginButton.hide();
			controler.loginToServer(getIp(), Integer.parseInt(getPort()), getLogin());
	    }                                          

	    /**
	     * Funkcja pobieraj�ca wpisany login.
	     */
	    public String getLogin()
	    {
	    	return loginField.getText();
	    }
	    
	    /**
	     * Funkcja pobiera wpisane IP.
	     */
	    public String getIp()
	    {
	    	return ipField.getText();
	    }
	    /**
	     * Funkcja pobierajaca port
	     */
	    public String getPort()
	    {
	    	return portField.getText();
	    }

}
